﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace aucn.web
{
    public enum ImageFloat
    {
        Left,
        Right,
        NoFloat
    }
    public partial class DecoratedImage : System.Web.UI.UserControl
    {
        private string imageUrl;
        private string altText;
        private int width;
        private ImageFloat imageFloat;
        private string boxMargin;
        private string linkUrl = string.Empty;
        private string addText = string.Empty;

        public int ImageWidth { get { return this.width; } set { this.width = value; this.ImageBox.Width = value + 10; } }
        public ImageFloat ImageFloat { get { return this.imageFloat; } 
            set 
            {
                this.imageFloat = value;
                string floatStyle;
                switch (value)
                {
                    case ImageFloat.Left:
                        floatStyle = "left";
                        break;
                    case ImageFloat.Right:
                        floatStyle = "right";
                        break;
                    default:
                        floatStyle = "none";
                        break;
                }
                ImageBox.Style.Add("float", floatStyle);
            } 
        }
        public string AdditionalTextLinkUrl { get { return this.linkUrl; } set { this.linkUrl = value.Trim(); } }
        public string AdditionalText { get { return this.addText; } set { this.addText = value.Trim(); } }
        public string ImageUrl { get { return this.imageUrl; } set { this.TheImage.ImageUrl = value; this.imageUrl = value; } }
        public string AlternateText { get { return this.altText; } set { this.TheImage.AlternateText = value; this.altText = value; } }
        public string BoxMargin 
        {
            get
            { return this.boxMargin; }
            set
            {
                this.boxMargin = value;
                this.ImageBox.Style.Add("margin", value);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.SetAdditionalText();
        }
        
        protected void SetAdditionalText()
        {
            try
            {
                if (string.IsNullOrEmpty(this.addText))
                {
                    this.pnText.Visible = false;
                }
                else
                {
                    string textToSet = addText;
                    if (this.linkUrl.Length > 0)
                    {
                        textToSet = string.Format("<a href='{0}'>{1}</a>", this.linkUrl, this.addText);
                    }
                    this.ltrText.Text = textToSet;
                }
            }
            catch { }
        }
    }
}